Repository navigation
feat: Cache context support for ReverseDiff.jl - #1093
franckgaga wants to merge 8 commits into
Conversation
- Optimize onearg.jl and twoarg.jl for better efficiency - Enhance utility functions in utils.jl - Add new tests in test.jl to ensure functionality
|
I'm not a vibe-coder at all normally. I will try to understand the main idea tomorrow and do some cleaning +114 lines is way too much for me, I'm sure it can be more concise. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1093 +/- ##
==========================================
- Coverage 98.18% 93.87% -4.32%
==========================================
Files 144 141 -3
Lines 8265 8258 -7
==========================================
- Hits 8115 7752 -363
- Misses 150 506 +356
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
gdalle
left a comment
There was a problem hiding this comment.
I'm not really worried about the length of the PR, it's more about understanding the mechanisms behind it :) thanks for giving this a shot!
| _sig = DI.signature(f, backend, x, contexts...; strict) | ||
| config = JacobianConfig(x) | ||
| return ReverseDiffOneArgJacobianPrep(_sig, config, nothing) | ||
| prep_contexts = translate_toprep(eltype(config.input), contexts) |
There was a problem hiding this comment.
If I understand correctly, the trick is to create an array of the appropriate TrackedReal element type? Shouldn't we rather have an TrackedArray? I'm not sure how these ReverseDiff internals work since they're not documented
There was a problem hiding this comment.
You are right, it's currently based on Array{TrackedReal}, not a ReverseDiff.TrackedArray. I will modify this.
There was a problem hiding this comment.
Okay so it seems that using ReverseDiff.TrackedArray for the cache is "impossible" with the current design in ReverseDiff.jl. In short, the TrackedArray wrapper is immutable and doesn’t support element assignment, see here: https://github.com/JuliaDiff/ReverseDiff.jl/blob/2584eaa222f616b64ebbcb815b7ceae0622da281/src/tracked.jl#L430. Since the whole point of the Cache is to mutate its content, I don't see a workaround. The Copilot neither.
FYI, PreallocationTools.jl also use a Array{TrackedReal} for the cache.
Fully agree ! I'm working on this today. Not easy for me since I'm unfamiliar with 3 layers: ReverseDiff internals, DifferentiationInterface internals and backpropagation. |
|
No stress! If you struggle too much, let me know and I'll take over. But I appreciate efforts to develop human expertise 💪 |
I will replicate what is tested in `ForwardDiff.jl`
The test suite pass locally on my side. Let's see on CI.
|
@gdalle Should I include the |
It seems to work on my side. Full Disclaimer: vibe-coded with my VS Code agents (Copilot Fusion).
Here's a MWE:
Closes #1092